<?php

function dbconnect(){
global $db;

$db = new Database(); 
if(!mysql_ping($db->connect())){
	if(isset($db)){$db->close();}
	$db = new Database(); 
$db->connect();
	}


}

function checkvars($id, $type=NULL){
			global $db;
dbconnect();

			$id =  $db->escape($id);	
			if($type){
			$sql2 = "select p_stm,u_stm from stream_stm where u_stm = '$id' and is_active_stm != 0";}
			else{
				$sql2 = "select p_stm,u_stm from stream_stm where p_stm = '$id' and is_active_stm != 0";
				}
$row = $db->query_first($sql2);

if(!empty($row['p_stm'])){
	$data6['is_active_stm'] = 1;
	$data6['date_stm'] = "NOW()"; 
	$db->query_update("stream_stm", $data6, "p_stm = '$id'");
	
	echo "&statuss=true&stream=$row[u_stm]";
	
	}else{
		echo "&statuss=false";
		}

			}
			
function disconnect($id){
global $db;
dbconnect();

$id =  $db->escape($id);
	$sql2 = "select p_stm from stream_stm where p_stm = '$id' and is_active_stm != 0";
	$row = $db->query_first($sql2);
if(!empty($row['p_stm'])){
$data6['is_active_stm'] = 3;
if($id){
$db->query_update("stream_stm", $data6, "p_stm = '$id'");
}
}
						
				}